package com.shop.user;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class UserController {

    private final UserService userService;

    @Autowired
    public UserController(UserService userService) {
        this.userService = userService;
    }

    @PostMapping("/user/findAll")
    public List<User> findAll() {
        return userService.findAll();
    }

    @PostMapping("/user/findPage")
    public List<User> findPage(@RequestBody Map<String, Integer> params) {
        int pageNumber = params.getOrDefault("pageNumber", 1);
        return userService.findPage(pageNumber);
    }

    @PostMapping("/user/findByUserid")
    public User findByUserid(@RequestBody Long userid) {
        return userService.findByUserid(userid);
    }

    @PostMapping("/user/findByUsername")
    public User findByUsername(@RequestBody String username) {
        return userService.findByUsername(username);
    }

    @PostMapping("/user/findByEmail")
    public User findByEmail(@RequestBody String email) {
        return userService.findByEmail(email);
    }

    @PostMapping("/user/insertUser")
    public int insertUser(@RequestBody User user) {
        return userService.insertUser(user);
    }

    @PostMapping("/user/updateUser")
    public int updateUser(@RequestBody User user) {
        return userService.updateUser(user);
    }

    @PostMapping("/user/deleteUser")
    public int deleteUser(@RequestBody Long userid) {
        return userService.deleteUser(userid);
    }
}
